Skip to content

[DO NOT MERGE] AgentCore samples: run activities in workflow activity sessions - #422

Draft
justinschoeff wants to merge 3 commits into
mainfrom
feature/activity-sessions
Draft

justinschoeff wants to merge 3 commits into
mainfrom
feature/activity-sessions

Conversation

@justinschoeff

Copy link
Copy Markdown
Contributor

Warning

Do not merge. Depends on the unreleased sdk-python dev/sticky-activities activity-session API (at e73f54d3) and on the unreleased session_options plugin argument (temporalio/ai-integrations#584). The samples resolve temporalio and the plugins from locally built wheels in the gitignored bedrock_agentcore/wheels/ directory via [tool.uv.sources] path sources, so CI cannot install them. Before merge, once the releases exist: delete build-local-wheels.sh and the path sources, pin the released versions, and re-lock.

What

Runs the AgentCore samples' activities (model calls, execute_code) inside the workflow's activity session. They execute on the same AgentCore microVM that holds the workflow.

  • bedrock_agentcore/build-local-wheels.sh (temporary): agentcore deploy (CodeZip) installs dependencies for Linux arm64, so this script builds the following into bedrock_agentcore/wheels/:
    • a manylinux2014 aarch64 temporalio wheel (in docker) and a macOS temporalio wheel, both labelled 1.34.0+sessions
    • the temporalio-strands-agents and temporalio-openai-agents wheels
  • Strands sample (strands_agent/):
    • Dependencies resolve from those wheels.
    • StrandsPlugin(session_options=ActivitySessionOptions(placement=UseWorkflowSession())).
    • The worker uses WorkerSessionConfig(admission=SingleSessionAdmission(stable_identity=<AgentCore session id>)), and falls back to no admission when there is no session id.
    • strands-agents-tools is capped at <0.9, because 0.9.0 removed code_interpreter and the deploy installs from pyproject.toml rather than uv.lock.
    • The README covers session placement, the server requirement and the wheel prerequisite.
  • New OpenAI Agents sample (openai_agent/):
    • Mirrors the Strands sample, using OpenAIAgentsPlugin(session_options=...) and the OpenAI API (OPENAI_API_KEY).
    • Its execute_code activity uses the bedrock_agentcore CodeInterpreter client.
    • Includes the deploy config, IAM policy, role template, scripts and README.

Commits

  1. Add script to build unreleased AgentCore sample deps
  2. Resolve Strands sample deps from local wheels
  3. Run Strands sample activities in workflow sessions
  4. Add AgentCore OpenAI Agents sample with activity sessions

Testing

Activity sessions are not yet in a released temporalio, nor is
session_options in the released AI plugins. agentcore deploy (CodeZip)
installs dependencies locally for Linux arm64 with uv, so the samples
need a Linux aarch64 temporalio wheel (plus an optional macOS one for
local runs) and both plugin wheels.

The script clones sdk-python and ai-integrations into .wheel-build/ at a
configurable repo URL and ref (branch, tag or SHA), reusing the clone on
re-runs; SDK_PYTHON_DIR / AI_INTEGRATIONS_DIR override with local
checkouts and SDK_CORE_REPO overrides the sdk-core submodule URL.

- temporalio is built as 1.34.0+sessions so it cannot be confused with
  the PyPI release; the Linux wheel is built in a manylinux2014 aarch64
  container, the macOS wheel is skipped when no cargo is available.
- Plugin wheels are built with --no-sources, ignoring ai-integrations'
  machine-local temporalio path source.
- wheels/BUILD_INFO records the resolved commits and wheel hashes.
- RELOCK=1 re-locks the samples after building.

Temporary; delete once the releases exist.
The plugin now fills ActivitySessionOptions(UseWorkflowSession()) so
model calls and execute_code run on the AgentCore microVM holding the
workflow. The worker admits a single session keyed on the AgentCore
session id, falling back to no admission without one.

Path sources pin temporalio (1.34.0+sessions) and
temporalio-strands-agents to ../wheels so neither can come from PyPI,
including in the uv pip install that agentcore deploy runs, and
create-runtime.sh checks the wheels exist. Also cap strands-agents-tools
below 0.9, which removed code_interpreter: the deploy installs from
pyproject.toml, not uv.lock, so it picked 0.9.

Document the session placement, the server requirement and building the
wheels with ../build-local-wheels.sh in the README.
Mirror the Strands AgentCore sample with the OpenAI Agents SDK:
OpenAIAgentsPlugin with session_options, a SingleSessionAdmission
Worker keyed on the AgentCore session, and an execute_code Activity on
the bedrock_agentcore CodeInterpreter client. Dependencies resolve from
the wheels built by ../build-local-wheels.sh.

Include the AgentCore deploy config (runtime temporal_openai_worker,
CodeZip, OPENAI_API_KEY placeholder), the Code Interpreter policy, the
invoke-role template and scripts (create-runtime.sh checks for the
openai plugin wheel), and a README.
@justinschoeff
justinschoeff force-pushed the feature/activity-sessions branch from 42fc96e to f3250be Compare November 16, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant